package cn.lvji.springboot.learn.exception.conf;

import java.util.Map;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

@Component
public class MyErrorAttributes  extends DefaultErrorAttributes {

    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        Throwable throwable = super.getError(webRequest);
        Map<String, Object> attrs = super.getErrorAttributes(webRequest, true);
        if(throwable instanceof ArithmeticException){
            attrs.put("arith", "1");
        }
        attrs.put("attr", "1");
        return attrs;
    }
}
